package com.yaowk.sfp.system.server.service.base;

import com.yaowk.sfp.system.api.model.Role;
import java.lang.Long;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import com.yaowk.sfp.system.server.dao.RoleDao;
import com.yaowk.sfp.common.db.BaseServiceImpl;
import java.lang.String;
import java.lang.Byte;
import com.yaowk.sfp.system.server.entity.SysRole;
import com.yaowk.sfp.system.server.service.IRoleService;

public abstract class RoleServiceBase extends BaseServiceImpl<Role, SysRole, Long> implements IRoleService {

	@Autowired
	private RoleDao dao;

	@Override protected RoleDao getDao() {
	return dao;
	}

	@Override
	public Role entity2Model(SysRole entity) {
		Role model = null;
		if(isNotEmpty(entity)){
			model = new Role();
			model.setId(entity.getId());
			model.setName(entity.getName());
			model.setDescription(entity.getDescription());
			model.setCreateTime(entity.getCreateTime());
			model.setCreateUserId(entity.getCreateUserId());
			model.setStatus(entity.getStatus());
		}
		return model;
	}

	@Override
	public SysRole model2Entity(Role model) {
		SysRole entity = null;
		if(isNotEmpty(model)){
			entity = new SysRole();
			entity.setId(model.getId());
			entity.setName(model.getName());
			entity.setDescription(model.getDescription());
			entity.setCreateTime(model.getCreateTime());
			entity.setCreateUserId(model.getCreateUserId());
			entity.setStatus(model.getStatus());
		}
		return entity;
	}

	@Override
	public SysRole updateParams(Role model) {
		SysRole entity = dao.findOne(model.getId());
		if(isNotEmpty(model.getName()))
			entity.setName(model.getName());
		if(isNotEmpty(model.getDescription()))
			entity.setDescription(model.getDescription());
		if(isNotEmpty(model.getCreateTime()))
			entity.setCreateTime(model.getCreateTime());
		if(isNotEmpty(model.getCreateUserId()))
			entity.setCreateUserId(model.getCreateUserId());
		if(isNotEmpty(model.getStatus()))
			entity.setStatus(model.getStatus());
		return entity;
	}


}